* Module 4

use cses4orig, clear

*-------------------------------------------------------------------------------
* 1. Recoding of variables
*-------------------------------------------------------------------------------

tab D1004
gen cntelec=D1004
label var cntelec "Country-election"
tab cntelec

tab D1006_NAM
gen cntry=D1006_NAM
lab var cntry "Country"
tab cntry

tab D2005
recode D2005 2=0 1=1 7/9=., gen (unionm)
label var unionm "Union membership" 
lab def unionm 0 "Non-member" 1 "Member"
lab val unionm unionm
tab unionm

gen age=.
replace age=(-D2001_Y+2013) if cntry=="Australia"
replace age=(-D2001_Y+2013) if cntry=="Austria"
replace age=(-D2001_Y+2015) if cntry=="Finland"
replace age=(-D2001_Y+2012) if cntry=="France"
replace age=(-D2001_Y+2013) if cntry=="Germany"
replace age=(-D2001_Y+2012) if cntry=="Greece"
replace age=(-D2001_Y+2013) if cntry=="Iceland"
replace age=(-D2001_Y+2011) if cntry=="Ireland"
replace age=(-D2001_Y+2011) if cntry=="New Zealand" &  cntelec== "NZL_2011"
replace age=(-D2001_Y+2014) if cntry=="New Zealand" &  cntelec== "NZL_2014"
replace age=(-D2001_Y+2013) if cntry=="Norway"
replace age=(-D2001_Y+2015) if cntry=="Portugal"
replace age=(-D2001_Y+2014) if cntry=="Sweden"
replace age=(-D2001_Y+2011) if cntry=="Switzerland"
replace age=(-D2001_Y+2015) if cntry=="Great Britain"
recode age -7988/-7982=.
recode age 9997/9999=.
label var age "Age" 
tab age
by cntry, sort: tab age

tab D2002
recode D2002 1=0 2=1 3=. 9=., gen (gender)
label var gender "Gender" 
lab def gender 0 "Male" 1 "Female"
lab val gender gender
tab gender

tab D2031
by cntry, sort: tab D2031 
recode D2031 1=1 2=2 3=3 4=4 7/9=., gen (locat)
label var locat "Location, rural-urban" 
lab def locat 1 "Village" 2 "Small/middle city" 3 "Suburbs" 4 "Large city"
lab val locat locat
tab locat

tab D2003
recode D2003 1/5=0 6/9=1 96/99=. , gen (educ)
label var educ "Education, 2 cat" 
lab def educ 0 "Non-tertiary education" 1 "Tertiary education" 
lab val educ educ
tab educ

*-------------------------------------------------------------------------------
* 2. Social class
*-------------------------------------------------------------------------------

* 2.1 Recode occupation variable (clasdtprep), recode employment status (status)

recode D2011 996/999=. 0/21=6 30/31=3 100/143=6 200/216=5 220/235=4 240/245=6 250/252=5 260/261=6 262/265=4 300/315=5 320/325=4 330/335=6 340/344=4 350/352=5 ///
400/441=3 500/552=1 600/835=2 900/913=1 920/933=2 940/952=1 960/962=2, gen (clasdtprep)
label var clasdtprep "Social class preparation, detailed" 
lab def clasdtprep 1 "Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers"
lab val clasdtprep clasdtprep
tab clasdtprep

tab D2012
by cntry, sort: tab D2012 
recode D2012 1/2=1 3/4=2 7/9=., gen (status)
label var status "Employment status" 
lab def status 1 "Employed" 2"Self-employed"
lab val status status
tab status

* 2.2 Combine occupation and status

gen clasdt=.
replace clasdt=1 if clasdtprep==1 & status==1 /*Serv + employed = serv workers*/
replace clasdt=2 if clasdtprep==2 & status==1 /*Prod + employed = prod workers*/
replace clasdt=3 if clasdtprep==3 & status==1 /*Clerks + employed = clerks*/
replace clasdt=4 if clasdtprep==4 & status==1 /*Socio + employed = socio-cult professionals*/
replace clasdt=5 if clasdtprep==5 & status==1 /*Tech + employed = technical professionals*/
replace clasdt=6 if clasdtprep==6 & status==1 /*Manag + employed = managers*/
replace clasdt=7 if (clasdtprep==1 & status==2) | (clasdtprep==2 & status==2) | (clasdtprep==3 & status==2) /*working class occupation + self-employed=small business*/
replace clasdt=8 if (clasdtprep==4 & status==2) | (clasdtprep==5 & status==2) | (clasdtprep==6 & status==2)  /*middle class occupation + self-employed=large empl/professional*/
label var clasdt "Social class, detailed" 
lab def clasdt 1"Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers" 7"Small business" 8"Large employers and self-employed prof"
lab val clasdt clasdt
tab clasdt


*-------------------------------------------------------------------------------
* 3. Voting behaviour - current election 
*-------------------------------------------------------------------------------

* 3.1 Creation of party5A variable from D3006_LH_PL for all countries except Australia, UK

recode D3006_LH_PL (88/99=200), gen (party5A)

replace party5A=3 if inlist(D3006_LH_PL, 3,7) & cntelec=="AUT_2013" /*Austria*/
replace party5A=2 if inlist(D3006_LH_PL, 1) & cntelec=="AUT_2013" /*Austria*/
replace party5A=10 if inlist(D3006_LH_PL, 4) & cntelec=="AUT_2013" /*Austria*/
replace party5A=11 if inlist(D3006_LH_PL, 8) & cntelec=="AUT_2013" /*Austria*/
replace party5A=0 if !inlist(D3006_LH_PL, 1,3,7,4,8) & !missing(party5A) & party5A!=200 & cntelec=="AUT_2013" 
tab party5A if cntelec=="AUT_2013"
tab D3006_LH_PL if cntelec=="AUT_2013"

replace party5A=3 if inlist(D3006_LH_PL, 3) & cntelec=="FIN_2015" /*Finland*/
replace party5A=2 if inlist(D3006_LH_PL, 4) & cntelec=="FIN_2015" /*Finland*/
replace party5A=10 if inlist(D3006_LH_PL, 5) & cntelec=="FIN_2015" /*Finland*/
replace party5A=11 if inlist(D3006_LH_PL, 6,11,13,14) & cntelec=="FIN_2015" /*Finland*/
replace party5A=0 if !inlist(D3006_LH_PL, 3,4,5,6,11,13,14 ) & !missing(party5A) & party5A!=200 & cntelec=="FIN_2015" 
tab party5A if cntelec=="FIN_2015"
tab D3006_LH_PL if cntelec=="FIN_2015"

replace party5A=3 if inlist(D3006_LH_PL, 8,14) & cntelec=="DEU_2013" /*Germany*/
replace party5A=2 if inlist(D3006_LH_PL, 4, 10) & cntelec=="DEU_2013" /*Germany*/
replace party5A=10 if inlist(D3006_LH_PL, 5) & cntelec=="DEU_2013" /*Germany*/
replace party5A=11 if inlist(D3006_LH_PL, 6) & cntelec=="DEU_2013" /*Germany*/
replace party5A=0 if !inlist(D3006_LH_PL, 4,5,6,10,8,14) & !missing(party5A) & party5A!=200 & cntelec=="DEU_2013" 
tab party5A if cntelec=="DEU_2013"
tab D3006_LH_PL if cntelec=="DEU_2013"

replace party5A=3 if inlist(D3006_LH_PL, 4,5,9) & cntelec=="GRC_2012" /*Greece*/
replace party5A=2 if inlist(D3006_LH_PL, 3) & cntelec=="GRC_2012" /*Greece*/
replace party5A=10 if inlist(D3006_LH_PL, 6,10,11) & cntelec=="GRC_2012" /*Greece*/
replace party5A=11 if inlist(D3006_LH_PL, 2,7) & cntelec=="GRC_2012" /*Greece*/
replace party5A=0 if !inlist(D3006_LH_PL, 2,3,6,7,10,11,4,5,9) & !missing(party5A) & party5A!=200 & cntelec=="GRC_2012" 
tab party5A if cntelec=="GRC_2012"
tab D3006_LH_PL if cntelec=="GRC_2012"

replace party5A=2 if inlist(D3006_LH_PL, 3) & cntelec=="ISL_2013" /*Iceland*/
replace party5A=11 if inlist(D3006_LH_PL, 4) & cntelec=="ISL_2013" /*Iceland*/
replace party5A=0 if !inlist(D3006_LH_PL, 3,4) & !missing(party5A) & party5A!=200 & cntelec=="ISL_2013" 
tab party5A if cntelec=="ISL_2013"
tab D3006_LH_PL if cntelec=="ISL_2013"

replace party5A=3 if inlist(D3006_LH_PL, 4) & cntelec=="NZL_2011" /*New Zealand*/
replace party5A=2 if inlist(D3006_LH_PL, 1) & cntelec=="NZL_2011" /*New Zealand*/
replace party5A=10 if inlist(D3006_LH_PL, 3,13) & cntelec=="NZL_2011" /*New Zealand*/
replace party5A=11 if inlist(D3006_LH_PL, 11) & cntelec=="NZL_2011" /*New Zealand*/
replace party5A=0 if !inlist(D3006_LH_PL, 1,3,11,13,4) & !missing(party5A) & party5A!=200 & cntelec=="NZL_2011" 
tab party5A if cntelec=="NZL_2011"
tab D3006_LH_PL if cntelec=="NZL_2011"

replace party5A=3 if inlist(D3006_LH_PL, 4) & cntelec=="NZL_2014" /*New Zealand*/
replace party5A=2 if inlist(D3006_LH_PL, 2) & cntelec=="NZL_2014" /*New Zealand*/
replace party5A=10 if inlist(D3006_LH_PL, 3) & cntelec=="NZL_2014" /*New Zealand*/
replace party5A=0 if !inlist(D3006_LH_PL, 2,3,4) & !missing(party5A) & party5A!=200 & cntelec=="NZL_2014" 
tab party5A if cntelec=="NZL_2014"
tab D3006_LH_PL if cntelec=="NZL_2014"

replace party5A=3 if inlist(D3006_LH_PL, 3) & cntelec=="NOR_2013" /*Norway*/
replace party5A=2 if inlist(D3006_LH_PL, 1) & cntelec=="NOR_2013" /*Norway*/
replace party5A=10 if inlist(D3006_LH_PL, 8,9) & cntelec=="NOR_2013" /*Norway*/
replace party5A=11 if inlist(D3006_LH_PL, 7) & cntelec=="NOR_2013" /*Norway*/
replace party5A=0 if !inlist(D3006_LH_PL, 1,7,8,9,3) & !missing(party5A) & party5A!=200 & cntelec=="NOR_2013" 
tab party5A if cntelec=="NOR_2013"
tab D3006_LH_PL if cntelec=="NOR_2013"

replace party5A=3 if inlist(D3006_LH_PL, 8) & cntelec=="SWE_2014" /*Sweden*/
replace party5A=2 if inlist(D3006_LH_PL, 2) & cntelec=="SWE_2014" /*Sweden*/
replace party5A=10 if inlist(D3006_LH_PL, 7,9) & cntelec=="SWE_2014" /*Sweden*/
replace party5A=11 if inlist(D3006_LH_PL, 1) & cntelec=="SWE_2014" /*Sweden*/
replace party5A=0 if !inlist(D3006_LH_PL, 1,2,7,9,8) & !missing(party5A) & party5A!=200 & cntelec=="SWE_2014" 
tab party5A if cntelec=="SWE_2014"
tab D3006_LH_PL if cntelec=="SWE_2014"

replace party5A=3 if inlist(D3006_LH_PL, 4,12,14,15,16) & cntelec=="CHE_2011" /*Switzerland*/
replace party5A=2 if inlist(D3006_LH_PL, 3) & cntelec=="CHE_2011" /*Switzerland*/
replace party5A=10 if inlist(D3006_LH_PL, 11) & cntelec=="CHE_2011" /*Switzerland*/
replace party5A=11 if inlist(D3006_LH_PL, 8, 21) & cntelec=="CHE_2011" /*Switzerland*/
replace party5A=0 if !inlist(D3006_LH_PL, 3,8,11,21,4,12,14,15,16) & !missing(party5A) & party5A!=200 & cntelec=="CHE_2011" 
tab party5A if cntelec=="CHE_2011"
tab D3006_LH_PL if cntelec=="CHE_2011"


*3.2 Creation of party5B variable from B3005_1 for Australia, UK

recode D3006_LH_DC (89/99=200), gen (party5B)

replace party5B=3 if inlist(D3006_LH_DC, 10) & cntelec=="AUS_2013" /*Australia*/
replace party5B=2 if inlist(D3006_LH_DC, 2) & cntelec=="AUS_2013" /*Australia*/
replace party5B=10 if inlist(D3006_LH_DC, 3) & cntelec=="AUS_2013" /*Australia*/
replace party5B=0 if !inlist(D3006_LH_DC, 2,3,10) & !missing(party5B) & party5B!=200 & cntelec=="AUS_2013" 
tab party5B if cntelec=="AUS_2013"
tab D3006_LH_DC if cntelec=="AUS_2013"

replace party5B=3 if inlist(D3006_LH_DC, 3) & cntelec=="GBR_2015" /*Great-Britain*/
replace party5B=2 if inlist(D3006_LH_DC, 2) & cntelec=="GBR_2015" /*Great-Britain*/
replace party5B=0 if !inlist(D3006_LH_DC, 2,3) & !missing(party5B) & party5B!=200 & cntelec=="GBR_2015" 
tab party5B if cntelec=="GBR_2015"
tab D3006_LH_DC if cntelec=="GBR_2015"


*3.3 Creation of party5C variable from D3006_PR_1 for France (1st round presidential election)

tab D3006_PR_1
recode D3006_PR_1 (93/99=200), gen (party5C)

replace party5C=3 if inlist(D3006_PR_1, 9) & cntelec=="FRA_2012" /*France*/
replace party5C=2 if inlist(D3006_PR_1, 5) & cntelec=="FRA_2012" /*France*/
replace party5C=10 if inlist(D3006_PR_1, 4) & cntelec=="FRA_2012" /*France*/
replace party5C=11 if inlist(D3006_PR_1, 1,2,3,11,12,16,18) & cntelec=="FRA_2012" /*France*/
replace party5C=0 if !inlist(D3006_PR_1, 1,2,3,4,5,11,12,16,18,9) & !missing(party5C) & party5C!=200 & cntelec=="FRA_2012" 
tab party5C if cntelec=="FRA_2012"
tab D3006_PR_1 if cntelec=="FRA_2012"


*3.4 Merge of the three variables in the new variable party

gen party5=party5A
replace party5=party5B if cntelec=="AUS_2013" | cntelec=="IRL_2011" | cntelec=="GBR_2015" 
replace party5=party5C if cntelec=="FRA_2012" 
label var party5 "Party choice, detailed"
lab def party5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5 party5
tab party5


* 3.5 Turnout

tab D3005_LH
recode D3005_LH 1=1 5=2 7/9=3, gen (turnout)
replace turnout=1 if D3005_PR_1==1 & cntelec=="FRA_2012"
replace turnout=2 if D3005_PR_1==5 & cntelec=="FRA_2012"
replace turnout=3 if D3005_PR_1==7 & cntelec=="FRA_2012"
label var turnout "Turnout" 
lab def turnout 1 "Voted" 2 "Not voted" 3 "Other"
lab val turnout turnout
tab turnout


* 3.6 Merge party and turnout: new variable party5abs

gen party5abs=party5
replace party5abs=4 if turnout==2 /*turnout: add a fourth category*/
replace party5abs=6 if turnout==3 /*other answer on turnout: add a sixth category*/  
label var party5abs "Party choice with abstainers, detailed"
lab def party5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5abs party5abs
tab party5abs



*-------------------------------------------------------------------------------
* 4. Voting behaviour - previous election
*-------------------------------------------------------------------------------

* 4.1 Creation of preparty5A variable from D3008_LH_PL for all countries except Australia and UK 

recode D3008_LH_PL (88/99=200), gen (preparty5A)

replace preparty5A=3 if inlist(D3008_LH_PL, 3,7) & cntelec=="AUT_2013" /*Austria*/
replace preparty5A=2 if inlist(D3008_LH_PL, 1) & cntelec=="AUT_2013" /*Austria*/
replace preparty5A=10 if inlist(D3008_LH_PL, 4) & cntelec=="AUT_2013" /*Austria*/
replace preparty5A=11 if inlist(D3008_LH_PL, 8) & cntelec=="AUT_2013" /*Austria*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 1,3,7,4,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="AUT_2013" 
tab preparty5A if cntelec=="AUT_2013"
tab D3008_LH_PL if cntelec=="AUT_2013"

replace preparty5A=3 if inlist(D3008_LH_PL, 3) & cntelec=="FIN_2015" /*Finland*/
replace preparty5A=2 if inlist(D3008_LH_PL, 4) & cntelec=="FIN_2015" /*Finland*/
replace preparty5A=10 if inlist(D3008_LH_PL, 5) & cntelec=="FIN_2015" /*Finland*/
replace preparty5A=11 if inlist(D3008_LH_PL, 6,11,13,14) & cntelec=="FIN_2015" /*Finland*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 3,4,5,6,11,13,14 ) & !missing(preparty5A) & preparty5A!=200 & cntelec=="FIN_2015" 
tab preparty5A if cntelec=="FIN_2015"
tab D3008_LH_PL if cntelec=="FIN_2015"

replace preparty5A=3 if inlist(D3008_LH_PL, 8,14) & cntelec=="DEU_2013" /*Germany*/
replace preparty5A=2 if inlist(D3008_LH_PL, 4, 10) & cntelec=="DEU_2013" /*Germany*/
replace preparty5A=10 if inlist(D3008_LH_PL, 5) & cntelec=="DEU_2013" /*Germany*/
replace preparty5A=11 if inlist(D3008_LH_PL, 6) & cntelec=="DEU_2013" /*Germany*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 4,5,6,10,8,14) & !missing(preparty5A) & preparty5A!=200 & cntelec=="DEU_2013" 
tab preparty5A if cntelec=="DEU_2013"
tab D3008_LH_PL if cntelec=="DEU_2013"

replace preparty5A=3 if inlist(D3008_LH_PL, 4,5,9) & cntelec=="GRC_2012" /*Greece*/
replace preparty5A=2 if inlist(D3008_LH_PL, 3) & cntelec=="GRC_2012" /*Greece*/
replace preparty5A=10 if inlist(D3008_LH_PL, 6,10,11) & cntelec=="GRC_2012" /*Greece*/
replace preparty5A=11 if inlist(D3008_LH_PL, 2,7) & cntelec=="GRC_2012" /*Greece*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 2,3,6,7,10,11,4,5,9) & !missing(preparty5A) & preparty5A!=200 & cntelec=="GRC_2012" 
tab preparty5A if cntelec=="GRC_2012"
tab D3008_LH_PL if cntelec=="GRC_2012"

replace preparty5A=2 if inlist(D3008_LH_PL, 3) & cntelec=="ISL_2013" /*Iceland*/
replace preparty5A=11 if inlist(D3008_LH_PL, 4) & cntelec=="ISL_2013" /*Iceland*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 3,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="ISL_2013" 
tab preparty5A if cntelec=="ISL_2013"
tab D3008_LH_PL if cntelec=="ISL_2013"

replace preparty5A=3 if inlist(D3008_LH_PL, 4) & cntelec=="NZL_2011" /*New Zealand*/
replace preparty5A=2 if inlist(D3008_LH_PL, 1) & cntelec=="NZL_2011" /*New Zealand*/
replace preparty5A=10 if inlist(D3008_LH_PL, 3,13) & cntelec=="NZL_2011" /*New Zealand*/
replace preparty5A=11 if inlist(D3008_LH_PL, 11) & cntelec=="NZL_2011" /*New Zealand*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 1,3,11,13,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NZL_2011" 
tab preparty5A if cntelec=="NZL_2011"
tab D3008_LH_PL if cntelec=="NZL_2011"

replace preparty5A=3 if inlist(D3008_LH_PL, 4) & cntelec=="NZL_2014" /*New Zealand*/
replace preparty5A=2 if inlist(D3008_LH_PL, 2) & cntelec=="NZL_2014" /*New Zealand*/
replace preparty5A=10 if inlist(D3008_LH_PL, 3) & cntelec=="NZL_2014" /*New Zealand*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 2,3,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NZL_2014" 
tab preparty5A if cntelec=="NZL_2014"
tab D3008_LH_PL if cntelec=="NZL_2014"

replace preparty5A=3 if inlist(D3008_LH_PL, 3) & cntelec=="NOR_2013" /*Norway*/
replace preparty5A=2 if inlist(D3008_LH_PL, 1) & cntelec=="NOR_2013" /*Norway*/
replace preparty5A=10 if inlist(D3008_LH_PL, 8,9) & cntelec=="NOR_2013" /*Norway*/
replace preparty5A=11 if inlist(D3008_LH_PL, 7) & cntelec=="NOR_2013" /*Norway*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 1,7,8,9,3) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NOR_2013" 
tab preparty5A if cntelec=="NOR_2013"
tab D3008_LH_PL if cntelec=="NOR_2013"

replace preparty5A=3 if inlist(D3008_LH_PL, 8) & cntelec=="SWE_2014" /*Sweden*/
replace preparty5A=2 if inlist(D3008_LH_PL, 2) & cntelec=="SWE_2014" /*Sweden*/
replace preparty5A=10 if inlist(D3008_LH_PL, 7,9) & cntelec=="SWE_2014" /*Sweden*/
replace preparty5A=11 if inlist(D3008_LH_PL, 1) & cntelec=="SWE_2014" /*Sweden*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 1,2,7,9,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="SWE_2014" 
tab preparty5A if cntelec=="SWE_2014"
tab D3008_LH_PL if cntelec=="SWE_2014"

replace preparty5A=3 if inlist(D3008_LH_PL, 4,12,14,15,16) & cntelec=="CHE_2011" /*Switzerland*/
replace preparty5A=2 if inlist(D3008_LH_PL, 3) & cntelec=="CHE_2011" /*Switzerland*/
replace preparty5A=10 if inlist(D3008_LH_PL, 11) & cntelec=="CHE_2011" /*Switzerland*/
replace preparty5A=11 if inlist(D3008_LH_PL, 8,21) & cntelec=="CHE_2011" /*Switzerland*/
replace preparty5A=0 if !inlist(D3008_LH_PL, 3,8,11,21,4,12,14,15,16) & !missing(preparty5A) & preparty5A!=200 & cntelec=="CHE_2011" 
tab preparty5A if cntelec=="CHE_2011"
tab D3008_LH_PL if cntelec=="CHE_2011"


*4.2 Creation of preparty5B variable from 3008_LH_DC for Australia

recode D3008_LH_DC (89/99=200), gen (preparty5B)

replace preparty5B=3 if inlist(D3008_LH_DC, 10) & cntelec=="AUS_2013" /*Australia*/
replace preparty5B=2 if inlist(D3008_LH_DC, 2) & cntelec=="AUS_2013" /*Australia*/
replace preparty5B=10 if inlist(D3008_LH_DC, 3) & cntelec=="AUS_2013" /*Australia*/
replace preparty5B=0 if !inlist(D3008_LH_DC, 2,3,10) & !missing(preparty5B) & preparty5B!=200 & cntelec=="AUS_2013" 
tab preparty5B if cntelec=="AUS_2013"
tab D3008_LH_DC if cntelec=="AUS_2013"

replace preparty5B=3 if inlist(D3008_LH_DC, 3) & cntelec=="GBR_2015" /*Great-Britain*/
replace preparty5B=2 if inlist(D3008_LH_DC, 2) & cntelec=="GBR_2015" /*Great-Britain*/
replace preparty5B=0 if !inlist(D3008_LH_DC, 2,3) & !missing(preparty5B) & preparty5B!=200 & cntelec=="GBR_2015" 
tab preparty5B if cntelec=="GBR_2015"
tab D3008_LH_DC if cntelec=="GBR_2015"


*4.3 Creation of preparty5C variable from D3008_PR_1

recode D3008_PR_1 (93/99=200), gen (preparty5C)

replace preparty5C=3 if inlist(D3008_PR_1, 9) & cntelec=="FRA_2012" /*France*/
replace preparty5C=2 if inlist(D3008_PR_1, 5) & cntelec=="FRA_2012" /*France*/
replace preparty5C=10 if inlist(D3008_PR_1, 4) & cntelec=="FRA_2012" /*France*/
replace preparty5C=11 if inlist(D3008_PR_1, 1,2,3,11,12,16,18) & cntelec=="FRA_2012" /*France*/
replace preparty5C=0 if !inlist(D3008_PR_1, 1,2,3,4,5,11,12,16,18,9) & !missing(preparty5C) & preparty5C!=200 & cntelec=="FRA_2012" 
tab preparty5C if cntelec=="FRA_2012"
tab D3008_PR_1 if cntelec=="FRA_2012"


*4.4 Merge of the three variables in the new variable preparty5

gen preparty5=preparty5A 
replace preparty5=preparty5B if cntelec=="AUS_2013" | cntelec=="GBR_2015" 
replace preparty5=preparty5C if cntelec=="FRA_2012" 
label var preparty5 "preparty choice, detailed"
lab def preparty5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5 preparty5
tab preparty5


*4.5 Pre-turnout
* For France: variable D3007_PR_1 

tab D3007_LH
recode D3007_LH 1=1 5=2 6=4 7/9=3, gen (preturnout)
replace preturnout=1 if D3007_PR_1==1 & cntelec=="FRA_2012"
replace preturnout=2 if D3007_PR_1==5 & cntelec=="FRA_2012"
replace preturnout=4 if D3007_PR_1==6 & cntelec=="FRA_2012"
replace preturnout=3 if D3007_PR_1==7 & cntelec=="FRA_2012"
replace preturnout=3 if D3007_PR_1==8 & cntelec=="FRA_2012"
label var preturnout "preturnout" 
lab def preturnout 1 "Voted" 2 "Not voted" 3 "Other" 4"Not eligible"
lab val preturnout preturnout
tab preturnout


*4.6 Merge preparty and preturnout: new variable preparty5abs

gen preparty5abs=preparty5
replace preparty5abs=4 if preturnout==2 /*turnout: add a fourth category*/ 
replace preparty5abs=5 if preturnout==4 /*not eligible: add a fifth category*/ 
replace preparty5abs=6 if preturnout==3 /*other answer on turnout: add a sixth category*/ 
label var preparty5abs "preparty choice with abstainers"
lab def preparty5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 5"Not eligible" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5abs preparty5abs
tab preparty5abs

tab preparty5


*-------------------------------------------------------------------------------
* 5. Finalize the data set
*-------------------------------------------------------------------------------

keep cntry cntelec unionm age gender locat educ clasdtprep status clasdt party5 turnout party5abs preparty5 preturnout preparty5abs

save cses4_rec, replace 
